/**
 * 
 */
package com.fruit.app.action.index.screen;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;

import com.fruit.app.common.page.Paginator.Paginator;
import com.fruit.app.model.Bouns;
import com.fruit.app.model.BounsExample;
import com.fruit.app.model.BounsItem;
import com.fruit.app.service.BounsService;
import com.opensymphony.xwork2.ActionSupport;

public class IndexAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4345141080253911480L;
	
	@Autowired
	private BounsService bounsService;

	private List<Bouns> bounsList;
	
	private Bouns bouns;
	
	private BounsExample bounsExample;
	
	private Date startTime;
	
	private Date endTime;
	
	private String year;
	
	private String month;
	
	private String memberCname;
	
	private Integer jxsLevel;
	
	private Paginator query;
	
	private BounsItem bounsItem;
	
	private List<BounsItem> bounsItemList;

	/**
	 * 当前页码[分页]
	 */
	private Integer currentPage;

	public List<BounsItem> getBounsItemList() {
		return bounsItemList;
	}

	public void setBounsItemList(List<BounsItem> bounsItemList) {
		this.bounsItemList = bounsItemList;
	}

	public BounsItem getBounsItem() {
		return bounsItem;
	}

	public void setBounsItem(BounsItem bounsItem) {
		this.bounsItem = bounsItem;
	}

	public Integer getJxsLevel() {
		return jxsLevel;
	}

	public void setJxsLevel(Integer jxsLevel) {
		this.jxsLevel = jxsLevel;
	}

	public String getYear() {
		return StringUtils.isBlank(year)?String.valueOf(Calendar.getInstance().get(Calendar.YEAR)):year;
	}

	public void setYear(String year) {
		this.year = year;
	}

	public String getMonth() {
		return month;
	}

	public void setMonth(String month) {
		this.month = month;
	}

	public String getMemberCname() {
		return memberCname;
	}

	public void setMemberCname(String memberCname) {
		this.memberCname = memberCname;
	}

	public Bouns getBouns() {
		return bouns;
	}

	public void setBouns(Bouns bouns) {
		this.bouns = bouns;
	}

	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	public List<Bouns> getBounsList() {
		return bounsList;
	}

	public void setBounsList(List<Bouns> bounsList) {
		this.bounsList = bounsList;
	}
	
	/**
	 * 显示月度折扣信息
	 * @return
	 */
	public String detailBouns(){
		bouns=bounsService.queryBounsBySaleMember(bouns);
		return "det";
	}
	
	/**
	 * 显示首页及查询信息
	 * @return
	 */
	public String selectBouns(){
		String salePeriod = null;
		if(StringUtils.isBlank(this.year) || StringUtils.isBlank(this.month)){
			salePeriod="";
		}else {
			salePeriod=year+"年"+month+"月";
		}
		bounsExample = new BounsExample();
		this.bounsExample.setItems(bounsService.getCount(salePeriod, memberCname, jxsLevel));
		this.bounsExample.setPage(getCurrentPage());
		bounsList=bounsService.queryByObject(salePeriod, memberCname, jxsLevel, this.bounsExample);
		this.bounsExample.setAction(ServletActionContext.getRequest().getRequestURL().toString());
		setQuery(bounsExample);
		return SUCCESS;
	}
	
	/**
	 * 显示月度培训信息
	 * @return
	 */
	public String itemBouns(){
		bounsItemList=bounsService.queryItemBySaleMember(bounsItem);
		bouns=bounsService.queryBounsBySaleMember(bouns);
		return "item";
	}
	
	public Integer getCurrentPage() {
		return currentPage!=null?currentPage:0;
	}

	public void setCurrentPage(Integer currentPage) {
		this.currentPage = currentPage;
	}
	
	public Paginator getQuery() {
		return query;
	}

	public void setQuery(Paginator query) {
		this.query = query;
	}
}
